import { addAppointment } from '../../../request/index.js';

Page({
  data: {
    selectedFamily: null,
    date: null,
    patients: null,
    index: 0,
    checked: true,
    isConfirm: false,
    week: ['周日','周一','周二','周三','周四','周五','周六'],
    doctor: null
  },
  onShow(){
    let selectedFamily = getApp().globalData.selectedFamily;
    let x = selectedFamily[0];
    let y = selectedFamily[1];
    let id = getApp().globalData.selectedDoctor;
    this.setData({selectedFamily: getApp().globalData.families[x][y],doctor: getApp().globalData.doctors[id]});
    let d = new Date();
    d.setDate(d.getDate() + 1);
    this.setData({date: d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + d.getDate()+ '  ' + this.data.week[d.getDay()]});
    this.setData({patients: getApp().globalData.patients});
  },
  bindPickerChange(e){
    this.setData({
      index: e.detail.value
    });
  },
  agree(){
    this.setData({checked: !this.data.checked});
  },
  confirm(){
    if(!this.data.checked)return;
    let _this = this;
    wx.showModal({
      title: '提示',
      content: '确认预约吗？',
      success(res){
        wx.showToast({
          title: '预约成功',
          icon: 'success',
          duration: 1000
        });
        if(res.confirm){
          _this.setData({isConfirm: true});
          //预约
        }
      }
    });
  },
  cancel(){
    let _this = this;
    wx.showModal({
      title: '提示',
      content: '确认取消预约吗？',
      success(res){
        if(res.confirm){
          _this.setData({isConfirm: false});
        }
        wx.showToast({
          title: '取消预约',
          icon: 'error'
        })
      }
    });
  },
  toIndex(){
    wx.switchTab({
      url: '../../index/index',
    })
  }
})